package com.mini.grpc.examples.helloworld;

import com.mini.grpc.client.CallOptions;
import com.mini.grpc.client.ClientCall;
import com.mini.grpc.client.netty.NettyClientCall;
import com.mini.grpc.common.Metadata;
import com.mini.grpc.common.MethodDescriptor;
import com.mini.grpc.common.Status;
import com.mini.grpc.serialization.StringMarshaller;
import com.mini.grpc.transport.netty.NettyClientTransport;

public class SimpleTest {
    public static void main(String[] args) {
        System.out.println("=== SimpleTest started ===");
        
        // 创建方法描述符
        MethodDescriptor<String, String> method = MethodDescriptor.<String, String>newBuilder()
            .setFullMethodName("/test.Service/testMethod")
            .setMethodType(MethodDescriptor.MethodType.UNARY)
            .setRequestMarshaller(StringMarshaller.INSTANCE)
            .setResponseMarshaller(StringMarshaller.INSTANCE)
            .build();
        
        // 创建传输（这里使用null，因为我们只是测试start方法）
        NettyClientTransport transport = null;
        
        // 创建NettyClientCall
        NettyClientCall<String, String> call = new NettyClientCall<>(method, CallOptions.DEFAULT, transport);
        
        System.out.println("Created NettyClientCall: " + call);
        
        // 创建监听器
        ClientCall.Listener<String> listener = new ClientCall.Listener<String>() {
            @Override
            public void onMessage(String message) {
                System.out.println("onMessage: " + message);
            }
            
            @Override
            public void onClose(Status status, Metadata trailers) {
                System.out.println("onClose: " + status);
            }
        };
        
        System.out.println("About to call start()");
        
        try {
            call.start(listener, new Metadata());
            System.out.println("start() completed");
        } catch (Exception e) {
            System.out.println("Exception in start(): " + e.getMessage());
            e.printStackTrace();
        }
        
        System.out.println("=== SimpleTest completed ===");
    }
} 